class ApplicationController < ActionController::Base
  protect_from_forgery
  
  before_filter :error_message_follows_field, :login_required
  
  respond_to :json,:html
  
  # 校验错误信息显示在field后面
  def error_message_follows_field
    error_message_follows_field_by_default
  end
  
  def error_message_follows_field_by_default
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|      
      if instance.error_message.kind_of?(Array)
        %(#{html_tag}<span class="validation_error">&nbsp;#{instance.error_message.join(',')}</span>).html_safe

      else
        %(#{html_tag}<span class= "validation_error">&nbsp;#{instance.error_message}</span>).html_safe
      end
    end
  end
  
  def login_required
#    authenticate_or_request_with_http_basic do |user_name,password|
#      logger.debug "user_name: #{user_name}    password:#{password}"
#      false
#    end
    Thread.current[:current_employee_id] = Employee.first.id
  end
end
